package com.base.myproject.client.busi.b2c;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.JDBCModelData;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;

public class B2cTree extends BaseJDBCPanel{
	BaseStore gcodestore  = null;
	BaseGrid gcodeegrid =null;
	public B2cTree() {
		super();
		init();
	}

	public void init() {

		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
	    centerData.setMargins(new Margins(5, 5, 0, 0));  
	this.add(initWeiget(),centerData);

	}
	public ContentPanel initWeiget() {
		ContentPanel panel = new ContentPanel();
		TabPanel tabpanel = new TabPanel();

		tabpanel.setAutoWidth(true);
	
		tabpanel.setAutoHeight(true);
		TabItem normal = new TabItem("商品显示方式定义");
	
		normal.add(CreateGcode());
		
		
		
		tabpanel.add(normal);

		
		panel.add(tabpanel);
		
		 setMaincomponent(gcodeegrid);
			registerMainStore(gcodestore);
			this.registerStore(gcodestore);

		return panel;
	}

	private ContentPanel CreateGcode()
	{
		ContentPanel panel = new ContentPanel();
		panel.setSize(400, 400);
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig treecode = new ColumnConfig("treecode", "商品显示方式编码", 100);
		TextField<String> treecodetext = new TextField<String>();
		treecode.setEditor(new CellEditor(treecodetext));
		columns.add(treecode);
		ColumnConfig treename = new ColumnConfig("treename", "商品显示方式名称", 100);
		TextField<String> treenametext = new TextField<String>();
		treename.setEditor(new CellEditor(treenametext));
		columns.add(treename);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("treecode");
		type.addField("treename");

		StoreInfo info = new StoreInfo();

		info.setTablename("b2cgcodetree");
		info.setKeyname(new String[]{"treecode"});
		info.setSql("select * from b2cgcodetree");
//		info.setParent(store);// 关联主表
//		info.setAutoinccolumn("idx"); // 自增字段，如果子表一定需要
//		info.setLinkparentcolumns(new String[] { "ccode" }); // 关联主表字段
		 gcodestore = new BaseStore<JDBCModelData>(type, info);
//		gudong.setName("gudong");
//		gudong.setKeyname(new String[] { "ccode", "idx" }); // 主键
		ColumnModel cm = new ColumnModel(columns);
		 gcodeegrid = new BaseGrid(gcodestore, cm);

		cbs.setSelectionMode(SelectionMode.SINGLE);

		gcodeegrid.setSelectionModel(cbs);
		gcodeegrid.setAutoHeight(true);
		gcodeegrid.setAutoWidth(true);

		registerStore(gcodestore);
		panel.add(gcodeegrid);
		panel.setScrollMode(Scroll.AUTO);
		return panel;
	}
	
}
